package com.mszlu.blog.config;

import com.mszlu.blog.handler.LoginIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Package: com.mszlu.blog.config
 * @ClassName: WebMvcConfig
 * @Author: 陈威
 * @CreateTime: 2021/8/27 13:34
 * @Description:
 */
@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {
    //登陆拦截器
    @Autowired
    LoginIntercepter loginIntercepter;

    //跨域配置
    @Override
    public void addCorsMappings(CorsRegistry registry) {
    /*    registry.addMapping("/**").allowedOrigins("*").allowCredentials(true)
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE","OPTIONS")
                .allowedOrigins("http://localhost:8080/");*/
        registry.addMapping("/**").allowedOrigins("http://localhost:8080");
      /*  registry.addMapping("/**").allowedOrigins("https://www.weigegeya.com");*/
    }

    //将登陆拦截器注册到spring中
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginIntercepter).addPathPatterns("/test").addPathPatterns("/comments/create/change","/articles/publish");
    }

}